import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';

import * as schema from '../database/schema';

export const tables = schema;
const env = useRuntimeConfig();
export function useDrizzle() {
  // Disable prefetch as it is not supported for "Transaction" pool mode
  const client = postgres(process.env.DATABASE_URL || env.public.DATABASE_URL, { prepare: false });
  const db = drizzle({ client });
  return db;
}

export type User = typeof schema.users.$inferSelect;
